package cn.edu.xhu.library_management.user.service.impl;


import cn.edu.xhu.library_management.user.entity.LmUserStudent;
import cn.edu.xhu.library_management.user.entity.search.TeacherSearch;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.edu.xhu.library_management.user.entity.LmUserTeacher;
import cn.edu.xhu.library_management.user.service.LmUserTeacherService;
import cn.edu.xhu.library_management.user.mapper.LmUserTeacherMapper;
import org.springframework.stereotype.Service;

/**
* @author 21086
* @description 针对表【lm_user_teacher(教师表)】的数据库操作Service实现
* @createDate 2023-04-18 08:58:28
*/
@Service
public class LmUserTeacherServiceImpl extends ServiceImpl<LmUserTeacherMapper, LmUserTeacher>
    implements LmUserTeacherService{

    @Override
    public Page<LmUserTeacher> search(TeacherSearch search) {
        Page<LmUserTeacher> page = new Page<>(search.getCurrentPage(), search.getPageSize());
        QueryWrapper<LmUserTeacher> wrapper = searchCondition(search);
        return this.page(page,wrapper);
    }

    /**
     * 搜索条件
     * @param search 搜索对象
     * @return 查询构造器
     */
    private QueryWrapper<LmUserTeacher> searchCondition(TeacherSearch search){
        QueryWrapper<LmUserTeacher> wrapper = new QueryWrapper<>();
        if (search.getThAccount() != null) {
            // 用户有账号
            wrapper.lambda().eq(LmUserTeacher::getThAccount, search.getThAccount());
        }
        if (search.getThName() != null) {
            // 姓名模糊查询
            wrapper.lambda().like(LmUserTeacher::getThName, search.getThName());
        }
        if (search.getThIscareer() != null) {
            // 是否锁定
            wrapper.lambda().eq(LmUserTeacher::getThIscareer, search.getThIscareer());
        }
        if (search.getThIslock() != null) {
            // 是否锁定
            wrapper.lambda().eq(LmUserTeacher::getThIslock, search.getThIslock());
        }

        if (search.getThMinBalance() != null && search.getThMaxBalance() != null){
            // 最小最大余额范围
            wrapper.lambda().between(LmUserTeacher::getThBalance,search.getThMinBalance(),search.getThMaxBalance());
        } else{
            if (search.getThMinBalance() != null) {
                // 大于等于
                wrapper.lambda().ge(LmUserTeacher::getThBalance,search.getThMinBalance());
            }else if (search.getThMaxBalance() != null){
                // 小于等于
                wrapper.lambda().le(LmUserTeacher::getThBalance,search.getThMaxBalance());
            }
        }
        if (search.getThMinBorrowNum() != null && search.getThMaxBorrowNum() != null){
            // 最小最大借阅范围
            wrapper.lambda().between(LmUserTeacher::getThBorrowNum,search.getThMinBorrowNum(),search.getThMaxBorrowNum());
        } else{
            if (search.getThMinBorrowNum() != null) {
                // 大于等于
                wrapper.lambda().ge(LmUserTeacher::getThBorrowNum,search.getThMinBorrowNum());
            }else if (search.getThMaxBorrowNum() != null){
                // 小于等于
                wrapper.lambda().le(LmUserTeacher::getThBorrowNum,search.getThMaxBorrowNum());
            }
        }



        return wrapper;
    }
}




